package com.syaccp.controller;

import com.syaccp.model.SysUser;
import com.syaccp.request.CustomerAddAndUpdateRequest;
import com.syaccp.request.CustomerSelectRequest;
import com.syaccp.service.CustomerService;
import com.syaccp.utils.Result;
import com.syaccp.utils.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "客户操作")
@RestController
@RequestMapping("/api/customer")
public class CustomerController {

    @Resource
    private CustomerService customerService;


    @ApiOperation(value = "根据登录用户查询客户页面头部信息")
    @GetMapping("/findCustomerHeader")
    public Result findCustomerHeader(){
        SysUser sysUser= SecurityUtil.getLoginUser();
        return customerService.findCustomerHeader(sysUser);
    }

    @ApiOperation(value = "根据传递过来的条件进行分页查询")
    @PostMapping("/findCustomer")
    public Result findCustomer(@RequestBody CustomerSelectRequest customerSelectRequest){
        System.out.println("customerSelectRequest = " + customerSelectRequest);
        return customerService.findCustomerPage(customerSelectRequest);
    }



    @ApiOperation(value = "根据传递过来的id查询客户对象")
    @GetMapping("/findCustomerById/{id}")
    public Result findCustomerById(@PathVariable Integer id){

        return customerService.findCustomerById(id);
    }


    @ApiOperation(value = "修改客户信息")
    @PutMapping("/updateCustomer")
    public Result updateCustomer(@RequestBody @Validated CustomerAddAndUpdateRequest caaur){
        System.out.println("caaur = " + caaur);

        return customerService.updateCustomer(caaur);
    }


    @ApiOperation(value = "新增客户信息")
    @PostMapping("/addCustomer")
    public Result addCustomer(@RequestBody @Validated CustomerAddAndUpdateRequest caaur){
        SysUser loginUser = SecurityUtil.getLoginUser();
        return customerService.addCustomer(caaur,loginUser);
    }


}
